;;; +markdown.el --- md -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

;; -------- markdown --------
(use-package markdown-mode
  :custom
  ;; if t, hide marker characters `*' etc.
  (markdown-hide-markup nil)
  (markdown-header-scaling t)
  (markdown-indent-function t)
  (markdown-enable-math t)
  (markdown-hide-urls nil)
  :mode ("README\\.md\\'" . gfm-mode) ;; GitHub Flavored Markdown
  :hook
  (markdown-mode . valign-mode)
  :config
  ;; 創建新的fontset後，以不同字體作爲CJK字符的`italic'形式，
  ;; 即西文的serif fonts (variable-pitch)，并指定使用場景。
  (create-fontset-from-fontset-spec
   (font-xlfd-name
    (font-spec :family "Source Serif Pro"
               :registry "fontset-variable_pitch")))
  (defun font-installed-p (font-name)
    "Check if font with FONT-NAME is available."
    (find-font (font-spec :name font-name)))
  (cl-loop for font in '("思源宋体 CN" "Source Han Serif CN"
                         "DejaVu Serif" "Noto Serif CJK SC")
           when (font-installed-p font) return
           (dolist (charset '(kana han symbol cjk-misc bopomofo))
             (set-fontset-font "fontset-variable_pitch" charset
                               (font-spec :family font) ;; 思源宋體
                               nil 'prepend)))
  (when (display-graphic-p)
    (dolist (face '(variable-pitch markdown-italic-face))
      (set-face-attribute face nil :fontset "fontset-variable_pitch")))
  :bind
  (:map markdown-mode-map
        ("C-c `" . 'markdown-insert-gfm-code-block)))

(provide '+markdown)

;;; +markdown.el ends here
